		
	***************************************************************************
	*** File name: Chin-Escriba-Song-Wright-CPS.do					 		***
	*** Author: jw joseph.g.wright@gmail.com								***
	*** Last updated: 04.13.2021											***
	***																		***	
	*** Using files:														***
	***		Chin-Escriba-Song-Wright.dta									***
	***		gandhi-sumner-estimates.xls										***
	***		weeks.dta														***
	***		cowcodes.do														***
	***																		***
	*** Using ado:															***
	***		xtsemipar														***
	***		xtdescribe														***
	***		sutex															***
	***		listtex															***
	***		reghdfe															***
	*** 	tuples															***
	***																		***
	***************************************************************************
		
		*** Set directory to access data ***
		global dir ="C:\Users\jgw12\Dropbox\Research\Pers-Assasination\Text\CPS\Chin-Escriba-Song-Wright-reproduction" 
		cd "$dir"
		*** Set directory to save plots ***
		global plots ="C:\Users\jgw12\Dropbox\Research\Pers-Assasination\Text\CPS\Chin-Escriba-Song-Wright-reproduction"
		
		capture log close
		log using Personalism-Assassins.log, replace

		set more off 
		set matsize 1000
		set scheme plotplain
		global seed ="984353"
		
		*** Set globals ***
		global bw= 3
		global id = "cow"
		global id2 = "gwf_caseid"
		global id3 = "gwf_leaderid"
		global t= "time time2"
		global d= "xpers"
		global x= "G_age lt leadermil loggdp logoil intwar civwar"   
		 
		*** Some basic descriptives ***
		use Chin-Escriba-Song-Wright,clear
		sum assa
		table coldwar,c(mean assa mean chcoup mean shcoup)
		table leadermil,c(mean assa mean chcoup mean shcoup)

		*** Set panel data ***
		xtset $id2 year
		xi:qui xtsemipar assa $t cyrs*,nonpar($d)nograph
		egen cnt=count(year) if e(sample)==1,by(cow)
		tab cnt
		*gen sample = e(sample)==1
		*recode sample (1=0) if cnt==1
		xtdescribe if sample==1
		xi:qui xtsemipar assa $t cyrs* $x if sample==1,nonpar($d)nograph
		*gen samplecov = e(sample)==1
		xtdescribe if samplecov==1
		label var lt "Leader time (log)"
		label var G_age "Leader age"
		label var leadermil "Military leader"
		label var loggdp "GDP pc (log)"
		label var logoil "Oil rents pc (log)"
		label var civwar "Civil conflict"
		label var intwar "Int'l conflict"
		label var assa "Assassination"
		label var chcoup "Regime change coup attempt"
		label var shcoup "Reshuffling coup attempt"
		label var ayrs "Time since assassination"
		label var cyrs "Time since coups"
		label var xpers "Personalism"
		label var support "Support party"
		sort cowcode year
		
		*** Summary statistics ***
		sutex shcoup chcoup assa cyrs ayrs lt G_age ///
			leadermil loggdp logoil civwar intwar xpers year ///
			if samplecov==1,minmax labels file($dir/Sumstats.tex) replace
		egen tag =tag(gwf_caseid) if samplecov==1
		egen max =max(year) if samplecov==1,by(gwf_caseid)
		egen min=min(year) if samplecov==1,by(gwf_caseid)
		sort gwf_country year
		*listtex gwf_casename min max if tag==1 using regimeslist.tex, rstyle(tabular) ///
		*	head("\begin{tabular}{l c c c}"" \textit{Regime-case} & \textit{Begin year} & \textit{End year}") ///
		*	foot("\end{tabular}") replace
		drop tag max min cnt
			
		*************************
		*** Reported analysis *** FE semiparametric per Baltagi and Li 2002
		*************************
		use Chin-Escriba-Song-Wright,clear
		centile xpers,centile(33.3 66.7)
		gen zper = xpers<=r(c_1) 
		replace zper =2 if xpers>r(c_1)  & xpers<=r(c_2) 
		replace zper =3 if xpers>=r(c_2)
		label define fl   1 "Low" 2 "Middle" 3 "High",replace
		label val zper fl
			*** TABLE 1 ***
		table zper,c(n xpers mean xpers mean shcoup mean chcoup mean assa) format(%9.4f)  
		table zper,c(mean xpers mean shcoup mean chcoup mean assa) format(%9.4f)  

		**********************
		** Degree selection **
		**********************
		use Chin-Escriba-Song-Wright,clear
		xtset $id2 year
		global y= "assa"
		local j=1
		forval i =1/6 {
 			xi:qui xtsemipar $y $t ayrs*,nonpar($d)cluster($id3)  deg(`i') spline  gen(fA`j' rA`j')  nograph
			di `i' 
			di e(rmse)
			di e(ll)
			local j=`j'+1
		}
		 twoway (lowess fA1 xpers,sort ytit(Probability of event)col(red*0.85)) ///
				(lowess fA2 xpers,sort ytit(Probability of event)col(red*0.85)) ///
				(lowess fA3 xpers,sort ytit(Probability of event)col(red*0.85)) ///
				(lowess fA4 xpers,sort ytit(Probability of event)col(red*0.85)) ///
				(lowess fA5 xpers,sort ytit(Probability of event)col(blue)lpat(solid)) ///
				(lowess fA6 xpers,sort ytit(Probability of event) saving(d1.gph,replace)   ///
				tit(Assassinations)legend(lab(1 "degree 1")lab(2 "degree 2") ///
				lab(3 "degree 3")lab(4 "degree 4")lab(5 "degree 5")lab(6 "degree 6")pos(10)ring(0))) 	 
		use Chin-Escriba-Song-Wright,clear
		xtset $id2 year
		global y= "chcoup"
		local j=1
		forval i =1/6 {
 			xi:qui xtsemipar $y $t cyrs*,nonpar($d)cluster($id3)  deg(`i') spline  gen(fA`j' rA`j')  nograph
			di `i' 
			di e(rmse)
			di e(ll)
			local j=`j'+1
		}
		 twoway (lowess fA1 xpers,sort ytit(Probability of event)col(red*0.85)) ///
				(lowess fA2 xpers,sort ytit(Probability of event)col(red*0.85)) ///
				(lowess fA3 xpers,sort ytit(Probability of event)col(blue)lpat(solid)) ///
				(lowess fA4 xpers,sort ytit(Probability of event)) ///
				(lowess fA5 xpers,sort ytit(Probability of event)saving(d2.gph,replace)) ///
				(lowess fA6 xpers,sort ytit(Probability of event)   ///
				tit(Regime change coups)legend(lab(1 "degree 1")lab(2 "degree 2") ///
				lab(3 "degree 3")lab(4 "degree 4")lab(5 "degree 5")lab(6 "degree 6")pos(7)ring(0))) 		
		use Chin-Escriba-Song-Wright,clear
		xtset $id2 year
		global y= "shcoup"
		local j=1
		forval i =1/6 {
 			xi:qui xtsemipar $y $t cyrs*,nonpar($d)cluster($id3)  deg(`i') spline  gen(fA`j' rA`j')   nograph
			di `i' 
			di e(rmse)
			di e(ll)
			local j=`j'+1
		}
		 twoway (lowess fA1 xpers,sort ytit(Probability of event)col(red*0.85)) ///
				(lowess fA2 xpers,sort ytit(Probability of event)col(red*0.85)) ///
				(lowess fA3 xpers,sort ytit(Probability of event)col(blue)lpat(solid)) ///
				(lowess fA4 xpers,sort ytit(Probability of event)) ///
				(lowess fA5 xpers,sort ytit(Probability of event)saving(d3.gph,replace)) ///
				(lowess fA6 xpers,sort ytit(Probability of event)   ///
				tit(Reshuffling coups)legend(lab(1 "degree 1")lab(2 "degree 2") ///
				lab(3 "degree 3")lab(4 "degree 4")lab(5 "degree 5")lab(6 "degree 6")pos(7)ring(0))) 			
		gr combine d1.gph d2.gph d3.gph,col(3) xsize(12)
		graph export "$plots\Figure-E-1.pdf", as(pdf)   replace
		
		******************
		* Assassinations *
		******************
			****************************
			* Semi-parametric analysis *
			****************************
			use Chin-Escriba-Song-Wright,clear
			xtset $id2 year
			global deg = 5
			global y= "assa"
			xi:xtsemipar $y $t ayrs* if sample==1,nonpar($d)cluster($id3)gen(fA rA)deg($deg) spline knots2(.15 .7)  nograph
			xi:xtsemipar $y $t ayrs* if sample==1 & xpers>0,nonpar($d)cluster($id3)gen(fA1 rA1)deg($deg) spline knots2(.15 .7)  nograph
			xi:xtsemipar $y $t ayrs* if sample==1 & xpers<1,nonpar($d)cluster($id3)gen(fA2 rA2)deg($deg) spline knots2(.15 .7)  nograph
			xi:xtsemipar $y $t $x ayrs* if sample==1,nonpar($d)cluster($id3) gen(fB rB)deg($deg) spline knots2(.15 .7) nograph
			xi:xtsemipar $y $t $x ayrs* if sample==1 & xpers>0.15,nonpar($d)cluster($id3) gen(fB1 rB1)deg($deg) spline knots2(.15 .7) nograph
			xi:xtsemipar $y $t $x ayrs* if sample==1 & xpers<1,nonpar($d)cluster($id3) gen(fB2 rB2)deg($deg) spline knots2(.15 .7) nograph
	 
					**********************************************************
					*** Rescale predicted values/residuals from LMP to 0,1 ***
					**********************************************************
						qui sum assa
						global amean=r(mean)
						local var ="fA rA fA1 rA1 fA2 rA2 fB rB fB1 rB1 fB2 rB2"
						foreach v of local var {
							replace `v'=invlogit(`v')
							qui sum `v'
							replace `v'=`v'-r(mean)+$amean
						}
 
			twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
				(line fA xpers,lcol(blue)lpat(solid)yscale(alt)yscale(range(-0.06 .02)alt axis(2))sort) ///
				(line fA1 xpers,lcol(cyan)lpat(dash)sort ylab(0(.01)0.03)lpat(solid)title(No covariate adjustment) ) ///
				(line fA2 xpers,lcol(red)lpat(dash)sort xtit("")ytit("Probability of assassination" "(partial)",height(0)) saving(fit1A.gph,replace) ///
				legend(lab(2 "All values")lab(3 "Exclude lowest")lab(4 "Exclude highest")order(2 3 4)pos(3)ring(0)))
				
			twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
				(line fB xpers,lcol(blue)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
				(line fB1 xpers,lcol(cyan)lpat(dash)sort ylab(0(0.01)0.03)lpat(solid)title(Covariate adjustment) ) ///
				(line fB2 xpers,lcol(red)lpat(dash)sort ytit("")xtit("")  /// 
				saving(fit2A.gph,replace) ///
				legend(lab(2 "All values")lab(3 "Exclude lowest")lab(4 "Exclude highest")order(2 3 4)pos(3)ring(0)))
			gr combine fit1A.gph fit2A.gph,xsize(8) title(Assassinations,size(large))name("assa", replace)cols(2)  
 			
			************************************** 
			* Two lines test: for Assassinations *
			************************************** 
			tsset $id3 year
			global xc = 0.13
			qui gen xlow1 = xpers-$xc if xpers<=$xc
			qui replace xlow1=0 if xpers>$xc
			qui gen xhigh1 =  xpers-$xc if xpers>$xc 
			qui replace xhigh1=0 if xpers<=$xc 
			qui gen hi1 = xpers>$xc		
			qui gen xlow2=xpers-$xc if xpers<$xc
			qui replace xlow2=0 if xpers>=$xc
			qui gen xhigh2=xpers-$xc if xpers>=$xc
			qui replace xhigh2=0 if xpers<$xc
			qui gen hi2 = xpers>=$xc
			gen x1=.
			gen x2=.
			gen y1=.
			gen y2=.
	
			* No covariate adjustment, xmax=1 *
			global xmax=1
			tsset $id3 year
 			qui reghdfe assa ayrs* xlow1 xhigh1 hi1 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow1==0
			test xhigh1=0,acc
			margins,dydx(xlow1)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xlow1]*$xc, post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x1=0 if _n==1
			replace x1=$xc if _n==2
			replace y1=`m' - (`b'/2) if _n==1
			replace y1=`m' + (`b'/2) if _n==2
			drop xb*
			qui reghdfe assa ayrs* xlow2 xhigh2 hi2 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow2==0
			test xhigh2=0,acc
			margins,dydx(xhigh2)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xhigh2]*($xmax-$xc), post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x2=$xc   if _n==1
			replace x2=$xmax if _n==2
			replace y2=`m' - (`b'/2) if _n==1
			replace y2=`m' + (`b'/2) if _n==2
			drop xb*
			replace y1=y1+($amean/2)
			replace y2=y2+($amean/2)
			twoway (line fA xpers,lpat(dash)lcol(gs10)sort) ///
 				(line y1 x1,lpat(solid)lcol(blue*1.1)ytit(Probability of assassination) ///
				xtit("")saving(fitT1A.gph,replace) ///
				legend(lab(1 "Nonlinear fit") lab(2 "Linear fit-1") lab(3 "Linear fit-2")order(1 2 3)col(1)ring(0)pos(5)) ///
				tit("All values of personalism") ) ///
				(line y2 x2,ylab(0(.01).03)lcol(red*1.1)lpat(solid) ///
				text(0.021 0.12  "{&beta}=-0.218" "p<0.154" ,size(small)) ///
				text(0.015 0.55 "{&beta}=0.004" "p<0.861",size(small)) ///
				text(0.010 0.4 "Joint test:" "p<0.340",size(small)))
			* No covariate adjustment, xmax=0.67 *
			global xmax=.67
			tsset $id3 year
			qui reghdfe assa ayrs* xlow1 xhigh1 hi1 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow1==0
			test xhigh1=0,acc
			margins,dydx(xlow1)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xlow1]*$xc, post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x1=0 if _n==1
			replace x1=$xc if _n==2
			replace y1=`m' - (`b'/2) if _n==1
			replace y1=`m' + (`b'/2) if _n==2
			drop xb*
			qui reghdfe assa ayrs* xlow2 xhigh2 hi2 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow2==0
			test xhigh2=0,acc
			margins,dydx(xhigh2)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xhigh2]*($xmax-$xc), post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x2=$xc   if _n==1
			replace x2=$xmax if _n==2
			replace y2=`m' - (`b'/2) if _n==1
			replace y2=`m' + (`b'/2) if _n==2
			drop xb*
			replace y1=y1+($amean/2)
			replace y2=y2+($amean/2)
			twoway (line fA xpers,lpat(dash)lcol(gs10)sort   ) ///
				(line y1 x1,lpat(solid)lcol(blue*1.1)ytit("") ///
				xtit("")saving(fitT2A.gph,replace) legend(lab(1 "Nonlinear fit") lab(2 "Linear fit-1") ///
				lab(3 "Linear fit-2")order(1 2 3)col(1)ring(0)pos(5)) tit("Personalism <= 0.67")) ///
				(line y2 x2,ylab(0(.01).03)lcol(red*1.1)lpat(solid) ///
				text(0.021 0.115  "{&beta}=-0.234" "p<0.141" ,size(small)) ///
				text(0.018 0.5 "{&beta}=0.062" "p<0.029",size(small)) ///
				text(0.007 0.45 "Joint test:" "p<0.024",size(small))) 
			gr combine fitT1A.gph fitT2A.gph,xsize(8) title(Assassinations,size(large))name("assaT", replace)cols(2) 
			
			* With covariate adjustment, xmax=1 *
			global xmax=1
			tsset $id3 year
			qui reghdfe assa ayrs* $x xlow1 xhigh1 hi1 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow1==0
			test xhigh1=0,acc
			margins,dydx(xlow1)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xlow1]*$xc, post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x1=0 if _n==1
			replace x1=$xc if _n==2
			replace y1=`m' - (`b'/2) if _n==1
			replace y1=`m' + (`b'/2) if _n==2
			drop xb*
			qui reghdfe assa ayrs* $x xlow2 xhigh2 hi2 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow2==0
			test xhigh2=0,acc
			margins,dydx(xhigh2)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xhigh2]*($xmax-$xc), post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x2=$xc   if _n==1
			replace x2=$xmax if _n==2
			replace y2=`m' - (`b'/2) if _n==1
			replace y2=`m' + (`b'/2) if _n==2
			drop xb*
			replace y1=y1+($amean/2)
			replace y2=y2+($amean/2)
			twoway (line fA xpers,lpat(dash)lcol(gs10)sort  ) ///
				(line y1 x1,lpat(solid)lcol(blue*1.1)ytit(Predicted probability of assassination) ///
				xtit(Personalism)saving(fit1.gph,replace) ///
				legend(lab(1 "Nonlinear fit") lab(2 "Linear fit-1") lab(3 "Linear fit-2")order(1 2 3)col(1)ring(0)pos(5)) ///
				tit("All values of personalism") ) ///
				(line y2 x2,ylab(0(.01).03)lcol(red*1.1)lpat(solid) ///
				text(0.025 0.1   "{&beta}=-0.251" "p<0.137" ,size(small)) ///
				text(0.015 0.45 "{&beta}=-0.006" "p<0.772",size(small)) ///
				text(0.005 0.5 "Joint test: p<0.336",size(small)))
			* With covariate adjustment, xmax=0.67 *
			global xmax=.67
			tsset $id3 year
			qui reghdfe assa ayrs* $x xlow1 xhigh1 hi1 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow1==0
			test xhigh1=0,acc
			margins,dydx(xlow1)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xlow1]*$xc, post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x1=0 if _n==1
			replace x1=$xc if _n==2
			replace y1=`m' - (`b'/2) if _n==1
			replace y1=`m' + (`b'/2) if _n==2
			drop xb*
			qui reghdfe assa ayrs* $x xlow2 xhigh2 hi2 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow2==0
			test xhigh2=0,acc
			margins,dydx(xhigh2)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xhigh2]*($xmax-$xc), post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x2=$xc   if _n==1
			replace x2=$xmax if _n==2
			replace y2=`m' - (`b'/2) if _n==1
			replace y2=`m' + (`b'/2) if _n==2
			drop xb*
			replace y1=y1+($amean/2)
			replace y2=y2+($amean/2)
			twoway (line fA xpers,lpat(dash)lcol(gs10)sort  ) ///
				(line y1 x1,lpat(solid)lcol(blue*1.1)ytit(Predicted probability of assassination) ///
				xtit(Personalism)saving(fit2.gph,replace) ///
				legend(lab(1 "Nonlinear fit") lab(2 "Linear fit-1") lab(3 "Linear fit-2")order(1 2 3)col(1)ring(0)pos(5)) ///
				tit("Personalism <= 0.67") ) ///
				(line y2 x2,ylab(0(.01).03)lcol(red*1.1)lpat(solid) ///
				text(0.025 0.1  "{&beta}=-0.254" "p<0.170" ,size(small)) ///
				text(0.02 0.53 "{&beta}=0.067" "p<0.019",size(small)) ///
				text(0.005 0.5 "Joint test: p<0.019",size(small))) 
			gr combine fit1.gph fit2.gph, xsize(8) title(Assassinations,size(large)) ///
				name("assaTC",replace)cols(2)  
			
			
		***********************
		* Regime change coups *
		***********************
			* Semiparametric *
			use Chin-Escriba-Song-Wright,clear
			xtset $id2 year
			global y= "chcoup"
			global deg=3
			xi:xtsemipar $y $t cyrs* if sample==1,nonpar($d)cluster($id3)gen(fA rA)deg($deg) nogr spline   
			xi:xtsemipar $y $t cyrs* if sample==1 & xpers>0,nonpar($d)cluster($id3)gen(fA1 rA1)deg($deg) nogr spline  
			xi:xtsemipar $y $t cyrs* if sample==1 & xpers<1,nonpar($d)cluster($id3)gen(fA2 rA2)deg($deg) nogr spline  
			xi:xtsemipar $y $t $x cyrs* if sample==1,nonpar($d)cluster($id3) gen(fB rB)deg($deg)nogr spline  
			xi:xtsemipar $y $t $x cyrs* if sample==1 & xpers>0,nonpar($d)cluster($id3) gen(fB1 rB1)deg($deg)nogr spline  
			xi:xtsemipar $y $t $x cyrs* if sample==1 & xpers<1,nonpar($d)cluster($id3) gen(fB2 rB2)deg($deg)nogr spline  
			
					**********************************************************
					*** Rescale predicted values/residuals from LMP to 0,1 ***
					**********************************************************
						qui sum $y
						global chmean=r(mean)
						local var ="fA rA fA1 rA1 fA2 rA2 fB rB fB1 rB1 fB2 rB2"
						foreach v of local var {
							replace `v'=invlogit(`v')
							qui sum `v'
							replace `v'=`v'-r(mean)+$chmean
						}
						
			twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
				(line fA xpers,lcol(blue)lpat(solid)sort yscale(alt)yscale(alt axis(2))title(No covariate adjustment)) ///
				(line fA1 xpers,lcol(cyan)lpat(dash)sort  ///
				xtit("")saving(fit1CH.gph,replace) yscale(range(0 .00))ylab(0(.02).06)) ///
				(line fA2 xpers,lcol(red)lpat(dash)sort xtit("")ytit("Probability of regime change coup" "(partial)",height(3)) ///
				legend(lab(2 "All values")lab(3 "Exclude lowest")lab(4 "Exclude highest")order(2 3 4)pos(1)ring(0))) 
			twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
				(line fB xpers,lcol(blue)lpat(solid)sort title(Covariate adjustment)) ///
				(line fB1 xpers,lcol(cyan)lpat(dash)yscale(alt)yscale(alt axis(2))sort saving(fit2CH.gph,replace)) ///
				(line fB2 xpers,lcol(red)lpat(dash)xtit("")ytit("")sort yscale(range(0 .00))ylab(0(.02).06) ///
				legend(lab(2 "All values")lab(3 "Exclude lowest")lab(4 "Exclude highest")order(2 3 4)pos(1)ring(0)))
			gr combine fit1CH.gph fit2CH.gph,xsize(8) title(Regime change coups,size(large))  name("chcoup", replace)cols(2) 
 		
			********************************************
			* Two lines tests: for Regime change coups *
			********************************************
			tsset $id3 year
			global xc = 0.413
			qui gen xlow1 = xpers-$xc if xpers<=$xc
			qui replace xlow1=0 if xpers>$xc
			qui gen xhigh1 =  xpers-$xc if xpers>$xc 
			qui replace xhigh1=0 if xpers<=$xc 
			qui gen hi1 = xpers>$xc		
			qui gen xlow2=xpers-$xc if xpers<$xc
			qui replace xlow2=0 if xpers>=$xc
			qui gen xhigh2=xpers-$xc if xpers>=$xc
			qui replace xhigh2=0 if xpers<$xc
			qui gen hi2 = xpers>=$xc
			gen x1=.
			gen x2=.
			gen y1=.
			gen y2=.
	
			* No covariate adjustment, xmax=1 *
			global xmax=1
			tsset $id3 year
			qui reghdfe chcoup cyrs* xlow1 xhigh1 hi1 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow1==0
			test xhigh1=0,acc
			margins,dydx(xlow1)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xlow1]*$xc, post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x1=0 if _n==1
			replace x1=$xc if _n==2
			replace y1=`m' - (`b'/2) if _n==1
			replace y1=`m' + (`b'/2) if _n==2
			drop xb*
			qui reghdfe chcoup cyrs* xlow2 xhigh2 hi2 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow2==0
			test xhigh2=0,acc
			margins,dydx(xhigh2)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xhigh2]*($xmax-$xc), post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x2=$xc   if _n==1
			replace x2=$xmax if _n==2
			replace y2=`m' - (`b'/2) if _n==1
			replace y2=`m' + (`b'/2) if _n==2
			drop xb*
			replace y1=y1+($chmean/2)
			replace y2=y2+($chmean/2)
			twoway (line fA xpers,lpat(dash)lcol(gs10)sort ) ///
				(line y1 x1,lpat(solid)lcol(blue*1.1)ytit(Probability of regime change coup) ///
				xtit("")saving(fitT1CH.gph,replace) ///
				legend(lab(1 "Nonlinear fit") lab(2 "Linear fit-1") lab(3 "Linear fit-2") ///
				order(1 2 3)col(3)ring(0)pos(6)) ///
				tit("All values of personalism") ) ///
				(line y2 x2,ylab(0(.02).06)lcol(red*1.1)lpat(solid) ///
				text(0.018 0.14  "{&beta}=0.098" "p<0.017" ,size(small)) ///
				text(0.024 0.68 "{&beta}=-0.070" "p<0.069",size(small)) ///
				text(0.009 0.45 "Joint test: p<0.014",size(small)))
			* No covariate adjustment, xmax=0.8 *
			global xmax=.8
			tsset $id3 year
			qui reghdfe chcoup cyrs* xlow1 xhigh1 hi1 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow1==0
			test xhigh1=0,acc
			margins,dydx(xlow1)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xlow1]*$xc, post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x1=0 if _n==1
			replace x1=$xc if _n==2
			replace y1=`m' - (`b'/2) if _n==1
			replace y1=`m' + (`b'/2) if _n==2
			drop xb*
			qui reghdfe chcoup cyrs* xlow2 xhigh2 hi2 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow2==0
			test xhigh2=0,acc
			margins,dydx(xhigh2)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xhigh2]*($xmax-$xc), post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x2=$xc   if _n==1
			replace x2=$xmax if _n==2
			replace y2=`m' - (`b'/2) if _n==1
			replace y2=`m' + (`b'/2) if _n==2
			drop xb*
			replace y1=y1+($chmean/2)
			replace y2=y2+($chmean/2)
			twoway (line fA xpers,lpat(dash)lcol(gs10)sort  ) ///
				(line y1 x1,lpat(solid)lcol(blue*1.1)ytit("") ///
				xtit("")saving(fitT2CH.gph,replace) ///
				legend(lab(1 "Nonlinear fit") lab(2 "Linear fit-1") lab(3 "Linear fit-2") ///
				order(1 2 3)col(3)ring(0)pos(6)) ///
				tit("Personalism <= 0.8") ) ///
				(line y2 x2,ylab(0(.02).06)lcol(red*1.1)lpat(solid) ///
				text(0.012 0.13  "{&beta}=0.117" "p<0.002" ,size(small)) ///
				text(0.012 0.85 "{&beta}=-0.156" "p<0.042",size(small)) ///
				text(0.012 0.45 "Joint test: p<0.001",size(small))) 
			gr combine fitT1CH.gph fitT2CH.gph,xsize(8) title(Regime change coups,size(large))  name("chcoupT", replace)cols(2) 
			
			* With covariate adjustment, xmax=1 *
			global xmax=1
			tsset $id3 year
			qui reghdfe chcoup cyrs* $x xlow1 xhigh1 hi1 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow1==0
			test xhigh1=0,acc
			margins,dydx(xlow1)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xlow1]*$xc, post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x1=0 if _n==1
			replace x1=$xc if _n==2
			replace y1=`m' - (`b'/2) if _n==1
			replace y1=`m' + (`b'/2) if _n==2
			drop xb*
			qui reghdfe chcoup cyrs* $x xlow2 xhigh2 hi2 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow2==0
			test xhigh2=0,acc
			margins,dydx(xhigh2)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xhigh2]*($xmax-$xc), post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x2=$xc   if _n==1
			replace x2=$xmax if _n==2
			replace y2=`m' - (`b'/2) if _n==1
			replace y2=`m' + (`b'/2) if _n==2
			drop xb*
			replace y1=y1+($chmean/2)
			replace y2=y2+($chmean/2)
			twoway (line fA xpers,lpat(dash)lcol(gs10)sort) ///
				(line y1 x1,lpat(solid)lcol(blue*1.1)ytit(Predicted probability of regime change coup) ///
				xtit(Personalism)saving(fit1.gph,replace) ///
				legend(lab(1 "Nonlinear fit") lab(2 "Linear fit-1") lab(3 "Linear fit-2") ///
				order(1 2 3)col(1)ring(0)pos(6)) tit("All values of personalism")) ///
				(line y2 x2,ylab(0(.02).06)lcol(red*1.1)lpat(solid) ///
				text(0.013 0.13  "{&beta}=0.123" "p<0.004" ,size(small)) ///
				text(0.018 0.72 "{&beta}=-0.074" "p<0.054",size(small)) ///
				text(0.05 0.8 "Joint test: p<0.005",size(small))) 
			* With covariate adjustment, xmax=0.9 *
			global xmax=.9
			tsset $id3 year
			qui reghdfe chcoup cyrs* $x xlow1 xhigh1 hi1 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow1==0
			test xhigh1=0,acc
			margins,dydx(xlow1)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xlow1]*$xc, post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x1=0 if _n==1
			replace x1=$xc if _n==2
			replace y1=`m' - (`b'/2) if _n==1
			replace y1=`m' + (`b'/2) if _n==2
			drop xb*
			qui reghdfe chcoup cyrs* $x xlow2 xhigh2 hi2 if xpers<=$xmax,absorb(year $id2) cluster($id3 year) 
			test xlow2==0
			test xhigh2=0,acc
			margins,dydx(xhigh2)
			predict xb,xb 
			gen xb1  = invlogit(xb)-.5
			qui sum xb1 if e(sample)==1
			local m = r(mean)
			di `m'
			nlcom _b[xhigh2]*($xmax-$xc), post 
			mat b=e(b)
			local b = b[1,1]
			di `b'
			replace x2=$xc   if _n==1
			replace x2=$xmax if _n==2
			replace y2=`m' - (`b'/2) if _n==1
			replace y2=`m' + (`b'/2) if _n==2
			drop xb*
			replace y1=y1+($chmean/2)
			replace y2=y2+($chmean/2)
			twoway (line fA xpers,lpat(dash)lcol(gs10)sort  ) ///
				(line y1 x1,lpat(solid)lcol(blue*1.1)ytit(Predicted probability of regime change coup) ///
				xtit(Personalism)saving(fit2.gph,replace) ///
				legend(lab(1 "Nonlinear fit") lab(2 "Linear fit-1") lab(3 "Linear fit-2") ///
				order(1 2 3)col(1)ring(0)pos(6)) ///
				tit("Personalism <= 0.8") ) ///
				(line y2 x2,ylab(0(.02).06)lcol(red*1.1)lpat(solid) ///
				text(0.013 0.13  "{&beta}=0.121" "p<0.004" ,size(small)) ///
				text(0.014 0.72 "{&beta}=-0.085" "p<0.083",size(small)) ///
				text(0.05 0.8 "Joint test: p<0.011",size(small))) 
			gr combine fit1.gph fit2.gph, xsize(8) title(Regime change coups,size(large)) ///
				name("chcoupTC",replace)cols(2)  
 		
		*********************
		* Reshuffling coups *
		*********************
			******************
			* Semiparametric *
			******************
			use Chin-Escriba-Song-Wright,clear
			xtset $id2 year
			global y= "shcoup"
			global deg=3
			xi:xtsemipar $y $t cyrs* if sample==1,nonpar($d)cluster($id3)gen(fA rA)deg($deg) spline  knots1(.25 .6) nograph
			xi:xtsemipar $y $t cyrs* if sample==1 & xpers>0,nonpar($d)cluster($id3)gen(fA1 rA1)deg($deg) spline  knots1(.25 .6) nograph
			xi:xtsemipar $y $t cyrs* if sample==1 & xpers<1,nonpar($d)cluster($id3)gen(fA2 rA2)deg($deg) spline  knots1(.25 .6) nograph
			xi:xtsemipar $y $t $x cyrs* if sample==1,nonpar($d)cluster($id3) gen(fB rB)deg($deg) spline knots1(.25 .6) nograph
			xi:xtsemipar $y $t $x cyrs* if sample==1 & xpers>0,nonpar($d)cluster($id3) gen(fB1 rB1)deg($deg) spline  knots1(.25 .6) nograph
			xi:xtsemipar $y $t $x cyrs* if sample==1 & xpers<1,nonpar($d)cluster($id3) gen(fB2 rB2)deg($deg) spline  knots1(.25 .6) nograph
			
					**********************************************************
					*** Rescale predicted values/residuals from LMP to 0,1 ***
					**********************************************************
						qui sum $y
						global shmean=r(mean)
						local var ="fA rA fA1 rA1 fA2 rA2 fB rB fB1 rB1 fB2 rB2"
						foreach v of local var {
							replace `v'=invlogit(`v')
							qui sum `v'
							replace `v'=`v'-r(mean)+$shmean
						}
			twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
				(line fA xpers,lcol(blue)lpat(solid)sort yscale(alt)yscale(alt axis(2)) title(No covariate adjustment)) ///
				(line fA1 xpers,lcol(cyan)lpat(dash)sort saving(fit1SH.gph,replace)ylab(0(.01).04)yscale(range(0 0.04))) ///
				(line fA2 xpers,lcol(red)lpat(dash)sort xtit("")ytit("Probability of reshuffling coup" "(partial)",height(1)) ///
				legend(lab(2 "All values")lab(3 "Exclude lowest")lab(4 "Exclude highest")pos(2)ring(0)order(2 3 4))) 
			twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
				(line fB xpers,lcol(blue)lpat(solid)sort yscale(alt)yscale(alt axis(2)) title(Covariate adjustment)) ///
				(line fB1 xpers,lcol(cyan)lpat(dash)sort saving(fit2SH.gph,replace)) ///
				(line fB2 xpers,lcol(red)lpat(dash)sort xtit("")ytit("")ylab(0(.01).04)yscale(range(0 0.04)) ///
				legend(lab(2 "All values")lab(3 "Exclude lowest")lab(4 "Exclude highest")pos(2)ring(0)order(2 3 4)))
			gr combine fit1SH.gph fit2SH.gph,xsize(8)title(Reshuffling coups,size(large))name("shcoup", replace)cols(2)  
 		
			gr combine shcoup chcoup assa,col(1)ysize(11)xsize(8)iscale(.6)  ///
				b1tit(Personalism index,size(small)height(0))
			graph export "$plots\Figure-2.pdf", as(pdf)   replace

			************************
			* One-line linear test *
			************************
			* One line test: No covariate adjustments *
			xtset $id3 year
			qui reghdfe $y cyrs* xpers,absorb(gwf_caseid time)cluster($id3 year) 
			lincom xpers 
			margins,dydx(xpers)  
			test xpers==0
 			predict xb if xpers<=1 & e(sample)==1,xb
			gen xb1 = invlogit(xb)-.5
			qui sum xb1
			replace xb1=xb1-r(mean)+  $shmean
			twoway (line fA xpers,lpat(dash)lcol(gs10)ylab(0(.01).04)sort) ///
				(lfit xb1 xpers if xpers<=1,lpat(solid)lcol(blue*1.1)ytit(Probability of reshuffle coup) ///
				xtit("")saving(fitT1SH.gph,replace) ///
				legend(lab(1 "Nonlinear fit") lab(2 "Linear fit") order(1 2)col(1)ring(0)pos(7)) ///
				tit("All values of personalism") ///
				text(0.006 0.495  "{&beta}=-0.053" "p<0.004" ,size(small)))
			drop xb xb1
			xtset $id3 year
			qui reghdfe $y cyrs* xpers if xpers<1,absorb(gwf_caseid time)cluster($id3 ) 
			lincom xpers 
			margins,dydx(xpers)  
			test xpers==0
			predict xb if xpers<1 & e(sample)==1,xb
			gen xb1 = invlogit(xb)-.5
			qui sum xb1
			replace xb1=xb1-r(mean)+  $shmean
			twoway (line fA xpers,lpat(dash)lcol(gs10)ylab(0(.01).04)sort  ) ///
				(lfit xb1 xpers if xpers<=1,lpat(solid)lcol(blue*1.1)ytit("") ///
				xtit("")saving(fitT2SH.gph,replace) ///
				legend(lab(1 "Nonlinear fit") lab(2 "Linear fit") order(1 2)col(1)ring(0)pos(7)) ///
				tit("Personalism <= 0.9")  ///
				text(0.006 0.515  "{&beta}=-0.057" "p<0.001" ,size(small)))			
			gr combine fitT1SH.gph fitT2SH.gph,xsize(8) title(Reshuffling coups,size(large))name("shcoupT", replace)cols(2)  
			gr combine shcoupT chcoupT assaT ,col(1)ysize(11)xsize(8)iscale(.6)  ///
				b1tit(Personalism index,size(vsmall)height(0))
			graph export "$plots\Figure-3.pdf",as(pdf)replace
			drop xb xb1
			
			* One line test: With covariate adjustments *
			xtset $id3 year
			qui reghdfe $y $x cyrs* xpers,absorb(gwf_caseid time)cluster($id3 year) 
			lincom xpers 
			margins,dydx(xpers)  
			test xpers==0
			predict xb if xpers<=1 & e(sample)==1,xb
			gen xb1 = invlogit(xb)-.5
			replace xb1=xb1+($shmean/2)
			twoway (line fB xpers,lpat(dash)lcol(gs10)ylab(0(.01).04)sort  ) ///
				(lfit xb1 xpers if xpers<=1,lpat(solid)lcol(blue*1.1)ytit(Predicted probability of reshuffle coup) ///
				xtit(Personalism)saving(fit1.gph,replace) ///
				legend(lab(1 "Nonlinear fit") lab(2 "Linear fit") order(1 2)col(1)ring(0)pos(7)) ///
				tit("All values of personalism")  ///
				text(0.01 0.48  "{&beta}=-0.055" "p<0.003" ,size(small)))
			drop xb xb1
			xtset $id3 year
			qui reghdfe $y $x cyrs* xpers if xpers<1,absorb(gwf_caseid time)cluster($id3 year) 
			lincom xpers 
			margins,dydx(xpers)  
			test xpers==0
			predict xb if xpers<1 & e(sample)==1,xb
			gen xb1 = invlogit(xb)-.5
			replace xb1=xb1+($shmean/2)
			twoway (line fB xpers,lpat(dash)lcol(gs10)ylab(0(.01).04) sort  ) ///
				(lfit xb1 xpers if xpers<=1,lpat(solid)lcol(blue*1.1)ytit(Predicted probability of reshuffle coup) ///
				xtit(Personalism)saving(fit2.gph,replace) ///
				legend(lab(1 "Nonlinear fit") lab(2 "Linear fit") order(1 2)col(1)ring(0)pos(7)) ///
				tit("Personalism <= 0.9")  ///
				text(0.0095 0.48  "{&beta}=-0.058" "p<0.01" ,size(small)))			
			gr combine fit1.gph fit2.gph,xsize(8) title(Reshuffling coups,size(large))name("shcoupTC", replace)cols(2)  
			gr combine shcoupTC chcoupTC assaTC,col(1)ysize(12)xsize(8)iscale(.5)  ///
				b1tit(Personalism index,size(vsmall)height(0))
			graph export "$plots\Figure-C-1.pdf",as(pdf)replace
 		
		*******************************************************************************
		*** Appendix B-1: Ambiguous assassinations/assassinations co-occur w/ coups ***
		*******************************************************************************
		use Chin-Escriba-Song-Wright,clear
		global deg=5 
		tab assa assassination
		tab assa assassination_nocoup_noamb
		tab assa assassination_noamb
			* Assassinations *
		xi:xtsemipar assa $t $x ayrs* if sample==1,ci ///
			nonpar($d) cluster($id2) gen(fB rB)deg($deg) spline knots2(.15 .7) nograph
		xi:xtsemipar assassination  $t ayrs* $x if samplecov==1,ci ///
			nonpar($d) cluster($id2) gen(f1 r1) deg($deg) spline knots2(.15 .7)  nograph
		xi:xtsemipar assassination_nocoup_noamb $t ayrs* $x if samplecov==1,ci ///
			nonpar($d) cluster($id2) gen(f2 r2) deg($deg) spline knots2(.15 .7) nograph 
		xi:xtsemipar assassination_noamb $t ayrs* $x if samplecov==1,ci ///
			nonpar($d) cluster($id2) gen(f3 r3)deg($deg) spline knots2(.15 .7)  nograph
		qui sum fB
		local m = r(mean)
		twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50) ///
			ylab(0(0)0,axis(2)) ytitle("",axis(2))) ///
			(line fB xpers,lpat(solid)sort lcol(blue)ylab(-.04(.02).04)) ///
			(line f1 xpers,lpat(dash)lcol(cyan*.58)sort ylab(-.04(.02).04)) ///
			(line f2 xpers,lpat(longdashdot)lcol(cyan*.58)sort ylab(-.04(.02).04)) ///
			(line f3 xpers,lpat(solid)lcol(cyan*.58)sort yscale(alt)yscale(alt axis(2)) ///
			xtitle("") ytitle("Probability of Assassination" "(partial)") ///
			title(Assassinations) yline(`m',lcol(red)lpat(solid)) ///
			legend(lab(2 "No coup, include ambiguous") lab(3 "Include coup") lab(4 "No coup, exclude ambiguous") ///
			lab(5 "Include coup & ambiguous") order(2 3 4 5)  pos(11) col(1) ring(0)))
		graph export "$plots\Figure-B-1.pdf", as(pdf)   replace		
		

		*****************************************  
		*** Appendix B-2: Assassination plots ***
		***************************************** 
			use Chin-Escriba-Song-Wright,clear
			gen assa_plot = assa
			recode assa_plot (0=1) if gwf_casename=="Cuba 59-NA" & year==	1961
			recode assa_plot (0=1) if gwf_casename=="Cuba 59-NA" & year==	1961
			recode assa_plot (0=1) if gwf_casename=="Cuba 59-NA" & year==	1963
			recode assa_plot (0=1) if gwf_casename=="Cuba 59-NA" & year==	1981
			recode assa_plot (0=1) if gwf_casename=="Haiti 57-86" & year==	1963
			recode assa_plot (0=1) if gwf_casename=="Mexico 15-00" & year==	1952
			recode assa_plot (0=1) if gwf_casename=="Nicaragua 36-79" & year==	1954
			recode assa_plot (0=1) if gwf_casename=="Bolivia 69-71" & year==	1971
			recode assa_plot (0=1) if gwf_casename=="Gambia 94-NA" & year==	1995
			recode assa_plot (0=1) if gwf_casename=="Benin 72-90" & year==	1988
			recode assa_plot (0=1) if gwf_casename=="Chad 82-90" & year==	1989
			recode assa_plot (0=1) if gwf_casename=="Congo/Zaire 60-97" & year==	1966
			recode assa_plot (0=1) if gwf_casename=="Libya 69-11" & year==	1981
			recode assa_plot (0=1) if gwf_casename=="Iran 79-NA" & year==	1982
			recode assa_plot (0=1) if gwf_casename=="Jordan 46-NA" & year==	1958
			recode assa_plot (0=1) if gwf_casename=="China 49-NA" & year==	1971
			recode assa_plot (0=1) if gwf_casename=="Myanmar 62-88" & year==	1976
			* Plots more likely at higher levels of personalism *
			gen plot = assa_plot==1  & assa==0
			probit plot time xpers,vce(cluster $id2)
			xtprobit plot time  xpers,vce(cluster $id2)
			tab assa assa_plot
			* Semiparametric *
			global deg = 5
			global y= "assa_plot"
			xi:xtsemipar $y $t ayrs* if sample==1,nonpar($d)cluster($id3)gen(fA rA)deg($deg) spline knots2(.15 .7)  nograph
 			xi:xtsemipar assa $t ayrs* if sample==1,nonpar($d)cluster($id3)gen(fA1 rA1)deg($deg) spline knots2(.15 .7)  nograph
			twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabel axis(2)) ytitle("",axis(2))) ///
				(line fA xpers,lcol(blue)lpat(solid)yscale(alt)yscale(range(-0.06 .02)alt axis(2))sort) ///
				(line fA1 xpers,lcol(red)lpat(dash)sort ylab(-0.06(0.02)0.02) title(No covariate adjustment)   ///
				 saving(fit1.gph,replace) ///
				legend(lab(2 "With plots")lab(3 "Without plots") order(2 3)pos(3)ring(0)))
			xi:xtsemipar $y $t $x ayrs* if sample==1,nonpar($d)cluster($id3) gen(fB rB)deg($deg) spline knots2(.15 .7) nograph
 			xi:xtsemipar assa $t $x ayrs* if sample==1,nonpar($d)cluster($id3)gen(fB1 rB1)deg($deg) spline knots2(.15 .7)  nograph
			twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabel axis(2)) ytitle("",axis(2))) ///
				(line fB xpers,lcol(blue)lpat(solid)yscale(alt)yscale(alt axis(2))sort  ) ///
				(line fB1 xpers,lcol(red)lpat(dash)sort ylab(-0.06(0.02)0.02)title(Covariate adjustment)  ///
				 saving(fit2.gph,replace) legend(lab(2 "With plots")lab(3 "Without plots") order(2 3)pos(3)ring(0)))
			gr combine fit1.gph fit2.gph,xsize(8) title(Assassinations attempts + reported plots)
			graph export "$plots\Figure-B-2.pdf", as(pdf)   replace
			
		**********************************************************
		*** Appendix E: additional BL tests for Assassinations ***
		**********************************************************		
		use Chin-Escriba-Song-Wright,clear
		xtset $id2 year
		global deg =5
		xi:xtsemipar assa $t $x ayrs* if sample==1,nonpar($d)cluster($id3)gen(fB rB)deg($deg)nogr spline knots2(.15 .7)   
			* Model specification adjustments *
		xi:xtsemipar assa time ayrs* $x,nonpar($d)cluster($id3)gen(f1 r1)deg($deg)nogr spline knots2(.15 .7)  
		xi:xtsemipar assa i.year ayrs* $x,nonpar($d)cluster($id3)gen(f2 r2)deg($deg)nogr spline knots2(.15 .7)  
		xi:xtsemipar assa time time2  ayrs* leadermil loggdp logoil civwar intwar, ///
			nonpar($d)cluster($id3)gen(f3 r3)deg($deg)nogr spline knots2(.15 .7) 
		xi:xtsemipar assa  time time2  ayrs* lt G_age loggdp logoil intwar civwar, ///
			nonpar($d)cluster($id3)gen(f4 r4)deg($deg)nogr spline knots2(.15 .7) 
		xi:xtsemipar assa  time time2  ayrs* lt G_age leadermil intwar civwar, ///
			nonpar($d)cluster($id3)gen(f5 r5)deg($deg)nogr spline knots2(.15 .7) 
		xi:xtsemipar assa  time time2   ayrs* lt G_age support leadermil loggdp logoil, ///
			nonpar($d)cluster($id3)gen(f6 r6)deg($deg)nogr spline knots2(.15 .7) 
		twoway (hist xpers,freq col(gs14)yaxis(2)bin(50)yscale(range(0 2500)axis(2))ylab(0(0)0,axis(2)) ytitle("",axis(2))) ///
			(line fB xpers,sort lcol(cyan)lpat(solid)) ///
			(line f1 xpers,sort  ) ///
			(line f2 xpers,sort  ) ///
			(line f3 xpers,sort  ) ///
			(line f4 xpers,sort  ) ///
			(line f5 xpers,sort  ) ///
			(line f6 xpers,sort ylab(-.04(.02).02)yscale(alt)yscale(alt axis(2))  ///
			xtitle(Personalism score,height(4)) ytitle(Probability of Assassination) ///
			title(Model specification adjustments) ///
			yline(0,lcol(red)lpat(dash)) ///
			legend(lab(1 "Personalism score") lab(2 "Full specification") ///
			lab(3 "Linear time trend") lab(4 "Year effects") lab(5 "Omit leader duration & age") ///
			lab(6 "Omit military leader") lab(7 "Omit GDPpc, Oil") lab(8 "Omit conflict")  ///
			pos(6) col(3) ring(1)size(small) order(2 3 4 5 6 7 8)))	
		graph export "$plots\Figure-E-2.pdf", as(pdf)   replace
		drop f6 r6 f5 r5 f4 r4 f3 r3 f2 r2 f1 r1 

			* Additional covariates in the specification *
		xi:qui xtsemipar assa $t ayrs* $x lpop,nonpar($d)cluster($id3)gen(f1 r1)deg($deg)nogr spline knots2(.15 .7) 
		xi:qui xtsemipar assa $t  ayrs* $x excluded,nonpar($d)cluster($id3)gen(f2 r2)deg($deg)nogr spline knots2(.15 .7) 
		xi:qui xtsemipar assa $t  ayrs* $x legcomp,nonpar($d)cluster($id3)gen(f3 r3)deg($deg)nogr spline knots2(.15 .7) 
		xi:qui xtsemipar assa $t  ayrs* $x nelda_inc,nonpar($d)cluster($id3)gen(f4 r4)deg($deg)nogr spline knots2(.15 .7) 
		xi:qui xtsemipar assa $t  ayrs* $x vkill3,nonpar($d)cluster($id3)gen(f5 r5)deg($deg)nogr spline knots2(.15 .7) 
		xi:qui xtsemipar assa $t  ayrs* $x lcyrs,nonpar($d)cluster($id3)gen(f6 r6)deg($deg)nogr spline knots2(.15 .7) 
		xi:qui xtsemipar assa $t  ayrs* $x nmc_logmilex,nonpar($d)cluster($id3)gen(f7 r7)deg($deg)nogr spline knots2(.15 .7) 
		xi:qui xtsemipar assa $t  ayrs* $x nmc_logmilper,nonpar($d)cluster($id3)gen(f8 r8)deg($deg)nogr spline knots2(.15 .7) 
		twoway (hist xpers,freq col(gs14)yaxis(2)bin(50)yscale(range(0 2500)axis(2))ylab(0(0)0,axis(2)) ytitle("",axis(2))) ///
			(line fB xpers,sort col(cyan)lpat(solid)) ///
			(line f1 xpers, sort) ///
			(line f2 xpers, sort) ///
			(line f3 xpers, sort) ///
			(line f4 xpers, sort) ///
			(line f5 xpers, sort) ///
			(line f6 xpers, sort) ///
			(line f7 xpers, sort) ///
			(line f8 xpers,sort ylab(-.04(.02).02)yscale(alt)yscale(alt axis(2))  ///
			xtitle(Personalism score,height(4)) ytitle(Probability of Assassination) ///
			title(Model specification adjustments) ///
			yline(0,lcol(red)lpat(dash)) ///
			legend(lab(2 "Baseline") lab(3 "Population") lab(4 "Ethnic exclusion") lab(5 "Institutions") ///
			 lab(6 "Election") lab(7 "Repression") lab(8 "Time since coup") ///
			 lab(9 "Military spending") lab(10 "Military personnel")  ///
			 pos(6) col(4) ring(1) order(2 3 4 5 6 7 8 9 10)))	
		graph export "$plots\Figure-E-3.pdf", as(pdf)   replace
		drop f8 r8 f7 r7 f6 r6 f5 r5 f4 r4 f3 r3 f2 r2 f1 r1 
	 
		* leave one out tests *
		gen iregion = 1 if cow<200
		replace iregion = 2 if cow>=200 & cow<400
		replace iregion = 3 if cow>=400 & cow<500
		replace iregion = 4 if cow>=500 & cow<600
		replace iregion = 5 if cow>=600 & cow<700
		replace iregion = 6 if cow>=700 
		forval i=1(1)6 {
			xi:qui xtsemipar assa $t ayrs* $x if iregion~=`i', nonpar($d)cluster($id3)gen(f`i' r`i')deg($deg)nogr spline knots2(.15 .7)  
		}
		twoway (hist xpers,freq col(gs14)yaxis(2)bin(50)yscale(range(0 2500)axis(2))ylab(0(0)0,axis(2)) ytitle("",axis(2))) ///
			(line fB xpers,sort col(cyan)lpat(solid)) ///
			(line f1 xpers, sort) ///
			(line f2 xpers, sort) ///
			(line f3 xpers, sort) ///
			(line f4 xpers, sort) ///
 			(line f5 xpers,sort col(red*.35)) ///
			(line f6 xpers,yscale(alt)yscale(alt axis(2))sort ///
			xtitle(Personalism score,height(4)) ytitle(Probability of Assassination) ///
			title(Leave-one-out-region) ///
			yline(0,lcol(red)lpat(dash)) ///
			legend(lab(2 "All") lab(3 "Americas") lab(4 "Europe") lab(5 "Central/West Africa") ///
			 lab(6 "East/Southern Africa") lab(7 "MENA") lab(8 "Asia")  ///
			 pos(12) col(3) ring(0) order(3 4 5 6 7 8 2)))	
		drop f6 r6 f5 r5 f4 r4 f3 r3 f2 r2 f1 r1 
		graph export "$plots\Figure-E-4.pdf", as(pdf)   replace
     
 		**********************************************************
		*** Appendix E: additional BL tests for Change coups ***
		**********************************************************	
		use Chin-Escriba-Song-Wright,clear
		global deg=3
		xtset $id2 year
		xi:xtsemipar chcoup $t $x cyrs* if sample==1,nograph  nonpar($d) cluster($id3) gen(fCHb rCHb)deg($deg) spline  
			* Model specification adjustments *
		xi:xtsemipar chcoup time cyrs* $x,nonpar(xpers) cluster($id3) gen(f1 r1) deg($deg)nograph spline  
		xi:xtsemipar chcoup $t  cyrs* $x,nonpar(xpers) cluster($id3) gen(f2 r2) deg($deg)nograph spline
		xi:xtsemipar chcoup $t  cyrs* leadermil loggdp logoil civwar intwar, ///
			nonpar(xpers) cluster($id3) gen(f3 r3) deg($deg)nograph	 spline
		xi:xtsemipar chcoup  $t  cyrs* lt G_age loggdp logoil intwar civwar, ///
			nonpar(xpers) cluster($id3) gen(f4 r4) deg($deg)nograph spline
		xi:xtsemipar chcoup  $t  cyrs* lt G_age leadermil intwar civwar, ///
			nonpar(xpers) cluster($id3) gen(f5 r5) deg($deg)nograph spline
		xi:xtsemipar chcoup  $t  cyrs* lt G_age leadermil loggdp logoil, ///
			nonpar(xpers) cluster($id3) gen(f6 r6) deg($deg)nograph spline
		twoway (hist xpers,freq col(gs14)yaxis(2)bin(50)yscale(range(0 2500)axis(2))ylab(0(0)0,axis(2)) ytitle("",axis(2))) ///
			(line fCHb xpers, sort lcol(cyan)lpat(solid)) ///
			(line f1 xpers,sort) ///
			(line f2 xpers,sort) ///
			(line f3 xpers,sort) ///
			(line f4 xpers,sort) ///
			(line f5 xpers,sort) ///
			(line f6 xpers,ylab(-.08(.04).04)yscale(alt)yscale(alt axis(2))sort ///
			xtitle(Personalism score,height(4)) ytitle(Probability of Regime change coups) ///
			title(Model specification adjustments) ///
			yline(0,lcol(red)lpat(dash)) ///
			legend(lab(1 "Personalism score") lab(2 "Full specification") ///
			lab(3 "Linear trend") lab(4 "Year effects") lab(5 "Omit leader variables") ///
			lab(6 "Omit military leader") lab(7 "Omit GDPpc, Oil") lab(8 "Omit conflict")  ///
			pos(6) col(3) ring(1)size(small) order(2 3 4 5 6 7 8)))	
		graph export "$plots\Figure-E-5.pdf", as(pdf)   replace
		drop f6 r6 f5 r5 f4 r4 f3 r3 f2 r2 f1 r1 

			* Additional covariates in the specification *
		xi:qui xtsemipar chcoup  $t cyrs* $x lpop,nogr nonpar(xpers) cluster($id3) gen(f1 r1) deg($deg)spline  
		xi:qui xtsemipar chcoup  $t cyrs* $x excluded,nogr nonpar(xpers) cluster($id3) gen(f2 r2) deg($deg)spline   
		xi:qui xtsemipar chcoup  $t cyrs* $x legcomp,nogr nonpar(xpers) cluster($id3) gen(f3 r3) deg($deg)spline  
		xi:qui xtsemipar chcoup  $t cyrs* $x nelda_inc,nogr nonpar(xpers) cluster($id3) gen(f4 r4) deg($deg)spline  
		xi:qui xtsemipar chcoup  $t cyrs* $x vkill3,nogr nonpar(xpers) cluster($id3) gen(f5 r5) deg($deg)spline  
		xi:qui xtsemipar chcoup  $t cyrs* $x layrs,nogr nonpar(xpers) cluster($id3) gen(f6 r6) deg($deg)spline  
		xi:qui xtsemipar chcoup  $t cyrs* $x nmc_logmilex,nogr nonpar(xpers) cluster($id3) gen(f7 r7) deg($deg)spline  
		xi:qui xtsemipar chcoup  $t cyrs* $x nmc_logmilper,nogr nonpar(xpers) cluster($id3) gen(f8 r8) deg($deg)spline  
		twoway (hist xpers,freq col(gs14)yaxis(2)bin(50)yscale(range(0 2500)axis(2))ylab(0(0)0,axis(2)) ytitle("",axis(2))) ///
			(line fCHb xpers, sort col(cyan)lpat(solid)) ///
			(line f1 xpers,sort) ///
			(line f2 xpers,sort) ///
			(line f3 xpers,sort) ///
			(line f4 xpers,sort) ///
			(line f5 xpers,sort) ///
			(line f6 xpers,sort) ///
			(line f7 xpers, sort) ///
			(line f8 xpers,ylab(-.08(.02).02)yscale(alt)yscale(alt axis(2)) sort ///
			xtitle(Personalism score,height(4)) ytitle(Probability of Regime change coups) ///
			title(Model specification adjustments) ///
			yline(0,lcol(red)lpat(dash)) ///
			legend(lab(2 "Baseline") lab(3 "Population") lab(4 "Ethnic exclusion") lab(5 "Institutions") ///
			 lab(6 "Election") lab(7 "Repression") lab(8 "Time since assassination") ///
			 lab(9 "Military spending") lab(10 "Military personnel")  ///
			 pos(6) col(4) ring(1)size(small) order(2 3 4 5 6 7 8 9 10)))	
		graph export "$plots\Figure-E-6.pdf", as(pdf)   replace
		drop f8 r8 f7 r7 f6 r6 f5 r5 f4 r4 f3 r3 f2 r2 f1 r1 
	 
		* leave one out tests *
		gen iregion = 1 if cow<200
		replace iregion = 2 if cow>=200 & cow<400
		replace iregion = 3 if cow>=400 & cow<500
		replace iregion = 4 if cow>=500 & cow<600
		replace iregion = 5 if cow>=600 & cow<700
		replace iregion = 6 if cow>=700 
		forval i=1(1)6 {
			xi:qui xtsemipar chcoup $t cyrs* $x if iregion~=`i',nogr spline nonpar(xpers) cluster($id3) gen(f`i' r`i') deg($deg)  
		}
		twoway (hist xpers,freq col(gs14)yaxis(2)bin(50)yscale(range(0 2500)axis(2))ylab(0(0)0,axis(2)) ytitle("",axis(2))) ///
			(line fCHb xpers, sort col(cyan)lpat(solid)) ///
			(line f1 xpers,sort) ///
			(line f2 xpers,sort) ///
			(line f3 xpers,sort) ///
			(line f4 xpers,sort) ///
			(line f5 xpers,sort) ///
			(line f6 xpers,yscale(alt)yscale(alt axis(2))sort ///
			xtitle(Personalism score,height(4)) ytitle(Probability of Regime change coups) ///
			title(Leave-one-out-region) ///
			yline(0,lcol(red)lpat(dash)) ///
			legend(lab(2 "All") lab(3 "Americas") lab(4 "Europe") lab(5 "Central/West Africa") ///
			 lab(6 "East/Southern Africa") lab(7 "MENA") lab(8 "Asia")  ///
			 pos(6) col(3) ring(1) order(3 4 5 6 7 8 2)))	
		drop f6 r6 f5 r5 f4 r4 f3 r3 f2 r2 f1 r1 
		graph export "$plots\Figure-E-7.pdf", as(pdf)   replace
		

		***********************************************************
		*** Appendix D-3: additional BL tests for Reshuffle coups ***
		***********************************************************
		use Chin-Escriba-Song-Wright,clear
		xtset $id2 year
		global deg=3
		xi:xtsemipar shcoup $t $x cyrs* if sample==1,nograph nonpar($d) cluster($id3) gen(fSHb rSHb)deg($deg) spline 

			* Model specification adjustments *
		xi:xtsemipar shcoup time cyrs* $x,nogr nonpar(xpers) cluster($id3) gen(f1 r1) deg($deg)   spline
		xi:xtsemipar shcoup $t cyrs* $x,nogr nonpar(xpers) cluster($id3) gen(f2 r2) deg($deg)   spline
		xi:xtsemipar shcoup $t cyrs*   leadermil  loggdp logoil civwar intwar, ///
			nogr nonpar(xpers) cluster($id3) gen(f3 r3) deg($deg)  	 spline
		xi:xtsemipar shcoup  $t cyrs* lt G_age loggdp logoil intwar civwar, ///
			nogr nonpar(xpers) cluster($id3) gen(f4 r4) deg($deg)   spline
		xi:xtsemipar shcoup $t cyrs* lt G_age leadermil intwar civwar, ///
			nogr nonpar(xpers) cluster($id3) gen(f5 r5) deg($deg)   spline
		xi:xtsemipar shcoup $t  cyrs* lt G_age leadermil  loggdp logoil, ///
			nogr nonpar(xpers) cluster($id3) gen(f6 r6) deg($deg)   spline
		twoway (hist xpers,freq col(gs14)yaxis(2)bin(50)yscale(range(0 2500)axis(2)) ///
			ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
			(line fSHb xpers,sort lcol(cyan)lpat(solid)) ///
			(line f1 xpers,sort) ///
			(line f2 xpers,sort) ///
			(line f3 xpers,sort) ///
			(line f4 xpers,sort) ///
			(line f5 xpers,sort) ///
			(line f6 xpers,ylab(-.08(.04).04)yscale(alt)yscale(alt axis(2))sort ///
			xtitle(Personalism score,height(4)) ytitle(Probability of Reshuffling coups) ///
			title(Model specification adjustments) ///
			yline(0,lcol(red)lpat(dash)) ///
			legend(lab(1 "Personalism score") lab(2 "Full specification") ///
			lab(3 "Linear trend") lab(4 "Nonlinear trend") lab(5 "Omit leader variables") ///
			lab(6 "Omit regime variables") lab(7 "Omit GDPpc, Oil") lab(8 "Omit conflict")  ///
			pos(6) col(3) ring(1)size(small) order(2 3 4 5 6 7 8)))	
		graph export "$plots\Figure-E-8.pdf", as(pdf)   replace
		drop f6 r6 f5 r5 f4 r4 f3 r3 f2 r2 f1 r1 

			* Additional covariates in the specification *
		xi:qui xtsemipar shcoup  $t  cyrs* $x lpop,nogr nonpar(xpers) cluster($id3) gen(f1 r1) deg($deg) spline
		xi:qui xtsemipar shcoup  $t  cyrs* $x excluded,nogr nonpar(xpers) cluster($id3) gen(f2 r2)  deg($deg) spline
		xi:qui xtsemipar shcoup  $t  cyrs* $x legcomp,nogr nonpar(xpers) cluster($id3) gen(f3 r3)  deg($deg) spline
		xi:qui xtsemipar shcoup  $t  cyrs* $x nelda_inc,nogr nonpar(xpers) cluster($id3) gen(f4 r4)  deg($deg) spline
		xi:qui xtsemipar shcoup  $t  cyrs* $x vkill3,nogr nonpar(xpers) cluster($id3) gen(f5 r5)  deg($deg) spline
		xi:qui xtsemipar shcoup  $t  cyrs* $x lcyrs,nogr nonpar(xpers) cluster($id3) gen(f6 r6)  deg($deg) spline
		xi:qui xtsemipar shcoup  $t  cyrs* $x nmc_logmilex,nogr nonpar(xpers) cluster($id3) gen(f7 r7) deg($deg) spline
		xi:qui xtsemipar shcoup  $t  cyrs* $x nmc_logmilper,nogr nonpar(xpers) cluster($id3) gen(f8 r8) deg($deg) spline
		twoway (hist xpers,freq col(gs14)yaxis(2)bin(50)yscale(range(0 2500)axis(2)) ///
			ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
			(line fSHb xpers,sort col(cyan)lpat(solid)) ///
			(line f1 xpers,sort) ///
			(line f2 xpers,sort) ///
			(line f3 xpers,sort) ///
			(line f4 xpers,sort) ///
			(line f5 xpers,sort) ///
			(line f6 xpers,sort) ///
			(line f7 xpers, sort) ///
			(line f8 xpers,ylab(-.08(.04).04)yscale(alt)yscale(alt axis(2)) sort ///
			xtitle(Personalism score,height(4)) ytitle(Probability of Reshuffle coups) ///
			title(Model specification adjustments) ///
			yline(0,lcol(red)lpat(dash)) ///
			legend(lab(2 "Baseline") lab(3 "Population") lab(4 "Ethnic exclusion") lab(5 "Leg comp") ///
			 lab(6 "Election") lab(7 "Repression") lab(8 "Time since coup") ///
			 lab(9 "Military spending") lab(10 "Military personnel")  ///
			 pos(6) col(4) ring(1) order(2 3 4 5 6 7 8 9 10)))	
		graph export "$plots\Figure-E-9.pdf", as(pdf)   replace
		drop f8 r8 f7 r7 f6 r6 f5 r5 f4 r4 f3 r3 f2 r2 f1 r1 
	 
		* leave one out tests *
		gen iregion = 1 if cow<200
		replace iregion = 2 if cow>=200 & cow<400
		replace iregion = 3 if cow>=400 & cow<500
		replace iregion = 4 if cow>=500 & cow<600
		replace iregion = 5 if cow>=600 & cow<700
		replace iregion = 6 if cow>=700 
		forval i=1(1)6 {
			xi:qui xtsemipar shcoup $t cyrs* $x if iregion~=`i',nogr nonpar(xpers) cluster($id3) gen(f`i' r`i') deg($deg) spline
		}
		twoway (hist xpers,freq col(gs14)yaxis(2)bin(50)yscale(range(0 2500)axis(2))ylab(0(0)0,axis(2)) ytitle("",axis(2))) ///
			(line fSHb xpers, sort col(cyan)lpat(solid)) ///
			(line f1 xpers,sort) ///
			(line f2 xpers,sort) ///
			(line f3 xpers,sort) ///
			(line f4 xpers,sort) ///
			(line f5 xpers,sort) ///
			(line f6 xpers,yscale(alt)yscale(alt axis(2))sort ///
			xtitle(Personalism score,height(4)) ytitle(Probability of Reshuffle coups) ///
			title(Leave-one-out-region) ///
			yline(0,lcol(red)lpat(dash)) ///
			legend(lab(2 "All") lab(3 "Americas") lab(4 "Europe") lab(5 "Central/West Africa") ///
			 lab(6 "East/Southern Africa") lab(7 "MENA") lab(8 "Asia")  ///
			 pos(6) col(3) ring(1) order(3 4 5 6 7 8 2)))	
		drop f6 r6 f5 r5 f4 r4 f3 r3 f2 r2 f1 r1 iregion*
		graph export "$plots\Figure-E-10.pdf", as(pdf)   replace
		
		 ************************
		 *** Drop first years ***
		 ************************
			use Chin-Escriba-Song-Wright,clear
			xtset $id2 year
			
			global y= "shcoup"
			global deg=3
			xi:xtsemipar $y $t cyrs* if sample==1 & gwf_case_duration>1,nonpar($d)cluster($id3)gen(fA rA)deg($deg) spline  knots1(.25 .6) nograph
			xi:xtsemipar $y $t cyrs* if sample==1,nonpar($d)cluster($id3)gen(fA1 rA1)deg($deg) spline  knots1(.25 .6) nograph
		
			global y= "chcoup"
			global deg=3
			xi:xtsemipar $y $t cyrs* if sample==1 & gwf_case_duration>1,nonpar($d)cluster($id3)gen(fB rB)deg($deg) nogr spline 
			xi:xtsemipar $y $t cyrs* if sample==1,nonpar($d)cluster($id3)gen(fB1 rB1)deg($deg) nogr spline 

			global y= "assa"
			global deg = 5
			xi:xtsemipar $y $t ayrs* if sample==1 & gwf_case_duration>1,nonpar($d)cluster($id3)gen(fC rC)deg($deg) spline knots2(.15 .7) nograph
			xi:xtsemipar $y $t ayrs* if sample==1,nonpar($d)cluster($id3)gen(fC1 rC1)deg($deg) spline knots2(.15 .7) nograph
				
			twoway (line fA xpers,sort) (line fA1 xpers,sort saving(fit1.gph,replace) ///
				legend(lab(1 "duration>1")lab(2 "all periods")pos(7)ring(0))tit(Reshuffle coups))			
			twoway (line fB xpers,sort) (line fB1 xpers,sort saving(fit2.gph,replace) ///
				legend(lab(1 "duration>1")lab(2 "all periods")pos(6)ring(0))tit(Regime change coups))
			twoway (line fC xpers,sort) (line fC1 xpers,sort saving(fit3.gph,replace) ///
				legend(lab(1 "duration>1")lab(2 "all periods")pos(5)ring(0))tit(Assassinations))
			gr combine fit1.gph fit2.gph fit3.gph, col(3) xsize(12)
			graph export "$plots\Figure-E-11.pdf", as(pdf)   replace
			

	**********************************************************************
	***** Mis-specification tests and functional form tests **************
	**********************************************************************
		use Chin-Escriba-Song-Wright,clear
		global bw= 3
		global id = "cow"
		global id2 = "gwf_caseid"
		global id3 = "gwf_leaderid"
		global t= "time time2"
		global d= "xpers"
		global x= "G_age lt leadermil loggdp logoil intwar civwar"
		global deg=5
								
		irt   (2pl officepers  milnotrial sectyapp_pers paramil_pers createparty partyexcom_pers partyrbr milmerit_persB)  
		predict xp, ebmeans latent
		qui sum xp 
		replace xp = xp+abs(r(min))
		sum xp
		gen xp2 = xp^2

		local var = "G_age lt loggdp logoil" 	
		foreach v of local var {
			gen sq`v'=`v'^2
		}
 
		global d = "xpers"
		xtset gwf_caseid year
		sort cowcod year
		save "$dir\temp-assassinations.dta",replace

		xi:xtsemipar assa $t ayrs*   if sample==1,nonpar($d)cluster($id3)gen(aA rA)deg($deg) spline knots2(.15 .7)  nograph
		xi:xtsemipar assa $t $x ayrs*   if sample==1,nonpar($d)cluster($id3)gen(aB rB)deg($deg) spline knots2(.15 .7) nograph 
		xi:xtsemipar assa $t $x sq* ayrs*  if sample==1,nonpar($d)cluster($id3)gen(aC rC)deg($deg) spline knots2(.15 .7)  nograph
		xi:xtsemipar chcoup $t cyrs* if sample==1,nonpar($d)cluster($id3)gen(chA rAch)deg($deg) spline knots2(.15 .7)  nograph
		xi:xtsemipar chcoup $t $x cyrs*   if sample==1,nonpar($d)cluster($id3)gen(chB rBch)deg($deg) spline knots2(.15 .7)  nograph
		xi:xtsemipar chcoup $t $x sq*   cyrs* if sample==1,nonpar($d)cluster($id3)gen(chC rCch)deg($deg) spline knots2(.15 .7)  nograph
		xi:xtsemipar shcoup $t   cyrs* if sample==1,nonpar($d)cluster($id3)gen(shA rAsh)deg($deg) spline knots2(.15 .7)  nograph
		xi:xtsemipar shcoup $t $x cyrs*   if sample==1,nonpar($d)cluster($id3)gen(shB rBsh)deg($deg) spline knots2(.15 .7)  nograph
		xi:xtsemipar shcoup $t $x sq*  cyrs* if sample==1,nonpar($d)cluster($id3)gen(shC rCsh)deg($deg) spline knots2(.15 .7)  nograph

		***************************************
		******** Plots with residuals *********
		***************************************
		twoway (scatter rA xpers  ,yaxis(2) yscale(alt)yscale(alt axis(2))mcol(gs12)) ///
			(lpolyci rA xpers,level(95)degree(3)bw(.35)lcol(blue)lpat(solid)legend(off) ///
			tit(Assassinations)xtit(Personalism)ytit(Residuals,axis(2)) ytit(Non-linear fit,axis(1)) ///
			note("Residuals and fit scales are not adjusted & thus represent residuals from a linear" "probability model that yields negative predicted values", ///
			size(vsmall)pos(6))saving(h3.gph,replace))
		twoway (scatter rAsh xpers  ,yaxis(2) yscale(alt)yscale(alt axis(2))mcol(gs12)) ///
			(lpolyci rAsh xpers,level(95)degree(3)bw(.35)lcol(blue)lpat(solid)legend(off) ///
			tit(Reshuffling coups)xtit(Personalism)ytit(Residuals,axis(2)) ytit(Non-linear fit,axis(1)) ///
			note("Residuals and fit scales are not adjusted & thus represent residuals from a linear" "probability model that yields negative predicted values", ///
			size(vsmall)pos(6))saving(h2.gph,replace))
		twoway (scatter rAch xpers  ,yaxis(2) yscale(alt)yscale(alt axis(2))mcol(gs12)) ///
			(lpolyci rAch xpers,level(95)degree(3)bw(.35)lcol(blue)lpat(solid)legend(off) ///
			tit(Regime change coups)xtit(Personalism)ytit(Residuals,axis(2)) ytit(Non-linear fit,axis(1)) ///
			note("Residuals and fit scales are not adjusted & thus represent residuals from a linear" "probability model that yields negative predicted values", ///
			size(vsmall)pos(6))saving(h1.gph,replace))
		gr combine h1.gph h2.gph h3.gph,col(3)xsize(8)ysize(3)
		gr export "$plots\Figure-E-12.pdf", as(pdf) replace

		qui sum assa
		global amean=r(mean)
		qui sum chcoup
		global cmean=r(mean)
		qui sum shcoup
		global smean=r(mean)

		local var ="rA aA rB aB rC aC rAch chA rBch chB rCch chC rAsh shA rBsh shB rCsh shC"
		foreach v of local var {
			replace `v'=invlogit(`v')
		}

		local var = "rA aA rB aB rC aC "
		foreach v of local var {
			qui sum `v'
			replace `v'=`v'-r(mean)+$amean
		}

		local var = "rAch chA rBch chB rCch chC"
		foreach v of local var {
			qui sum `v'
			replace `v'=`v'-r(mean)+$cmean
		}

		local var = "rAsh shA rBsh shB rCsh shC"
		foreach v of local var {
			qui sum `v'
			replace `v'=`v'-r(mean)+$smean
		}
			 
		* Misspecification tests *
		twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
			(line aA xpers,lcol(blue)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(line aB xpers,lcol(red)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(line aC xpers,lcol(cyan)lpat(solid)yscale(alt)yscale(alt axis(2))sort saving(h3.gph,replace)  ///
			legend(lab(2 "no covariate adjustment")lab(3 "covariate adjustment")lab(4 "over-specified")order(2 3 4)pos(10)ring(0)) ///
			tit(Assassinations)ytit(Event probability)xtit(Personalism)ylab(.01(.01).03))  
		twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
			(line chA xpers,lcol(blue)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(line chB xpers,lcol(red)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(line chC xpers,lcol(cyan)lpat(solid)yscale(alt)yscale(alt axis(2))sort saving(h1.gph,replace)    ///
			legend(lab(2 "no covariate adjustment")lab(3 "covariate adjustment")lab(4 "over-specified")order(2 3 4)pos(1)ring(0)) ///
			tit(Regime change coups)ytit(Event probability)xtit(Personalism) ylab(.02(.01).05))
		twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
			(line shA xpers,lcol(blue)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(line shB xpers,lcol(red)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(line shC xpers,lcol(cyan)lpat(solid)yscale(alt)yscale(alt axis(2))sort saving(h2.gph,replace)   ///
			legend(lab(2 "no covariate adjustment")lab(3 "covariate adjustment")lab(4 "over-specified")order(2 3 4)pos(1)ring(0)) ///
			tit(Reshuffling coups)ytit(Event probability)xtit(Personalism) ylab(.01(.01).04) ) 
		gr combine h1.gph h2.gph h3.gph,col(3)xsize(8)ysize(3)
		gr export "$plots\Figure-E-15.pdf", as(pdf) replace
			 
		* Estimate quadratic fit of residuals *
		qui reg rA xp xp2,cluster(gwf_leaderid) 
		qui predict hat_A,xb
		qui reg rAch xp xp2,cluster(gwf_leaderid) 
		qui predict hat_Ach,xb
		qui reg rAsh xp xp2,cluster(gwf_leaderid) 
		qui predict hat_Ash,xb

		 * Assassinations polynomial fit with CI *
		 twoway (lpolyci rA xpers,level(95)degree(3)bw(.35)lcol(ltblue)lpat(solid) legend(lab(3 "Nonparametric fit")  ///
			lab(4 "Linear fit of residuals") lab(5 "Quadratic fit of residuals") lab(2 "Polynomial fit of residuals")   ///
			pos(4)ring(0)order(2 3 4 5))xtit(Personalism)ytit(Event probability)tit(Assassinations)saving(h3.gph,replace)) ///
			(line aA xpers,sort lpat(solid)lcol(magenta))(lfit rA xpers,lcol(green)lpat(solid)) ///
			(lpoly hat_A xpers,sort deg(2) lcol(cyan)lpat(solid)ylab(.005(.01).035)yline(.02,lcol(red)lpat(solid)))
		 * Reg change coups polynomial fit with CI *
		 twoway (lpolyci rAch xpers,level(95)degree(3)bw(.3)lcol(ltblue)lpat(solid) legend(lab(3 "Nonparametric fit")  ///
			lab(4 "Linear fit of residuals") lab(5 "Quadratic fit of residuals") lab(2 "Polynomial fit of residuals")   ///
			pos(7)ring(0)order(2 3 4 5))xtit(Personalism)ytit(Event probability)tit(Regime change coups)saving(h1.gph,replace)) ///
			(line chA xpers,sort lpat(solid)lcol(magenta))(lfit rAch xpers,lcol(green)lpat(solid)) ///
			(lpoly hat_Ach xpers,sort deg(2) lcol(cyan)lpat(solid)ylab(.01(.01).06)yline(.041,lcol(red)lpat(solid)))
		 * Reshuffling coups polynomial fit with CI *
		 twoway (lpolyci rAsh xpers,level(95)degree(3)bw(.3)lcol(ltblue)lpat(solid) legend(lab(3 "Nonparametric fit")  ///
			lab(4 "Linear fit of residuals") lab(5 "Quadratic fit of residuals") lab(2 "Polynomial fit of residuals")   ///
			pos(7)ring(0)order(2 3 4 5))xtit(Personalism)ytit(Event probability)tit(Reshuffling coups)saving(h2.gph,replace)) ///
			(line shA xpers,sort lpat(solid)lcol(magenta))(lfit rAsh xpers,lcol(green)lpat(solid)) ///
			(lpoly hat_Ash xpers,sort deg(2) lcol(cyan)lpat(solid)ylab(.0(.01).04)yline(.025,lcol(red)lpat(solid)))
		gr combine h1.gph h2.gph h3.gph,col(3)xsize(8)ysize(3)
		gr export "$plots\Figure-D-1.pdf", as(pdf) replace
		 
		gen xp3 = xp^3
		qui reg rAch xp xp2 xp3,cluster(gwf_leaderid)
		qui predict hat3_Ach,xb		
		twoway (scatter chA xpers if xpers<=.2,sort mcol(blue))  (line chA xpers if xpers<=.2,sort lpat(solid) lcol(blue)) ///
			(scatter hat_Ach xpers if xpers<=.2,mcol(red)) (lpoly hat_Ach xpers if xpers<=.2,sort lcol(red)lpat(solid)deg(2)bw(.05))  ///
			(scatter hat3_Ach xpers if xpers<=.2,mcol(green)) (lpoly hat3_Ach xpers if xpers<=.2,sort lcol(green)lpat(solid)deg(2) ///
			bw(.1)legend(lab(2 "Semiparametric fit") lab(4 "Quadratic fit of residuals") lab(6 "Cubic fit of residuals") ///
			order(2 4 6)pos(5)ring(0))ylab(.045(.005).055)ytit(Coup probability)xtit(Personalism))
		 gr export "$plots\Figure-D-2.pdf", as(pdf) replace


	**************************************************
	***** Semiparametric by institutionalization *****
	**************************************************
		egen minyr = min(year),by(gwf_caseid)
		gen fm = leadermil==1 if min==year
		egen firstmil = max(fm),by(gwf_caseid)   
		twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
			(line chA xpers,lcol(blue)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(lpoly rAch xpers if firstmil==1,degree(3)bw(.45)lcol(red)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(lpoly rAch xpers if firstmil==0,degree(3)bw(.45)lcol(cyan)lpat(solid)yscale(alt)yscale(alt axis(2))sort saving(h1.gph,replace)    ///
			legend(lab(2 "Semiparametic fit (all)")lab(3 "Residual fit for military")lab(4 "Residual fit for non-military")order(2 3 4)pos(1)ring(0)) ///
			tit(Regime change coups)ytit(Event probability)xtit(Personalism) ylab(.02(.01).05))
		twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
			(line shA xpers, lcol(blue)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(lpoly rAsh xpers if firstmil==1,degree(3)bw(.45)lcol(red)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(lpoly rAsh xpers if firstmil==0,degree(3)bw(.5)lcol(cyan)lpat(solid)yscale(alt)yscale(alt axis(2))sort saving(h2.gph,replace)    ///
			legend(lab(2 "Semiparametic fit (all)")lab(3 "Residual fit for military")lab(4 "Residual fit for non-military")order(2 3 4)pos(7)ring(0)) ///
			tit(Reshuffle coups)ytit(Event probability)xtit(Personalism) ylab(.0(.01).04))
		twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
			(line aA xpers, lcol(blue)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(lpoly rA xpers if firstmil==1,degree(3)bw(.45)lcol(red)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(lpoly rA xpers if firstmil==0,degree(3)bw(.45)lcol(cyan)lpat(solid)yscale(alt)yscale(alt axis(2))sort saving(h3.gph,replace)    ///
			legend(lab(2 "Semiparametic fit (all)")lab(3 "Residual fit for military")lab(4 "Residual fit for non-military")order(2 3 4)pos(5)ring(0)) ///
			tit(Assassinations)ytit(Event probability)xtit(Personalism) ylab(.01(.01).03))
		gr combine h1.gph h2.gph h3.gph,col(3)xsize(8)ysize(3)
		gr export "$plots\Figure-E-13.pdf", as(pdf) replace

		twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
			(line chA xpers,lcol(blue)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(lpoly rAch xpers if inherit==1,degree(3)bw(.45)lcol(red)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(lpoly rAch xpers if inherit==0,degree(3)bw(.45)lcol(cyan)lpat(solid)yscale(alt)yscale(alt axis(2))sort saving(h1.gph,replace)    ///
			legend(lab(2 "Semiparametic fit (all)")lab(3 "Residual fit for inherited party")lab(4 "Residual fit for non-party")order(2 3 4)pos(1)ring(0)) ///
			tit(Regime change coups)ytit(Event probability)xtit(Personalism) ylab(.02(.01).05))
		twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
			(line shA xpers, lcol(blue)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(lpoly rAsh xpers if inherit==1,degree(3)bw(.45)lcol(red)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(lpoly rAsh xpers if inherit==0,degree(3)bw(.5)lcol(cyan)lpat(solid)yscale(alt)yscale(alt axis(2))sort saving(h2.gph,replace)    ///
			legend(lab(2 "Semiparametic fit (all)")lab(3 "Residual fit for inherited party")lab(4 "Residual fit for non-party")order(2 3 4)pos(7)ring(0)) ///
			tit(Reshuffle coups)ytit(Event probability)xtit(Personalism) ylab(.0(.01).04))
		twoway (hist xpers,freq col(gs14)yscale(range(0 2500)axis(2))yaxis(2)bin(50)ylab(0(0)0,nolabels axis(2)) ytitle("",axis(2))) ///
			(line aA xpers, lcol(blue)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(lpoly rA xpers if inherit==1,degree(3)bw(.45)lcol(red)lpat(solid)yscale(alt)yscale(alt axis(2))sort) ///
			(lpoly rA xpers if inherit==0,degree(3)bw(.45)lcol(cyan)lpat(solid)yscale(alt)yscale(alt axis(2))sort saving(h3.gph,replace)    ///
			legend(lab(2 "Semiparametic fit (all)")lab(3 "Residual fit for inherited party")lab(4 "Residual fit for non-party")order(2 3 4)pos(5)ring(0)) ///
			tit(Assassinations)ytit(Event probability)xtit(Personalism) ylab(.01(.01).03))
		gr combine h1.gph h2.gph h3.gph,col(3)xsize(8)ysize(3)
		gr export "$plots\Figure-E-14.pdf", as(pdf) replace

 
	************************************************************************************
	***************** Comparison with Gandhi-Sumner and Weeks data *********************
	************************************************************************************
		import excel "$dir\gandhi-sumner-estimates.xls" ,firstrow clear
		set scheme plotplain
		gen cowcode = .
		qui do cowcodes
		replace cowcode = 145 if country=="Bolivia, Plurinational State of"
		replace cowcode = 265 if country=="German Democratic Republic"
		replace cowcode = 713 if country=="Taiwan, Province of China"
		replace cowcode = 680 if country=="Yemen People's Republic"  
		tab country if cowcode==.
		drop if cowcode==.
		sort cowcode year 
		merge cowcode year using "Chin-Escriba-Song-Wright.dta"
		tab _merge
		rename _merge gwf_gs_merge
		sort cowcode year
		merge cowcode year using weeks
		tab _merge
		drop if _merge==2
		
		irt  (2pl officepers  milnotrial sectyapp_pers paramil_pers create partyrbr partyexcom_pers milmerit_persB)  
		predict xp if e(sample)==1,ebmeans latent
		qui sum xp
		replace xp = xp + abs(r(min))
		gen gs = xhatmean
		qui sum gs 
		replace gs =gs + abs(r(min))
		sum gs
		gen gs2 = gs^2
		qui sum xp
		replace xp = xp/(r(max))
		qui sum xhatmean
		replace xhatmean =xhatmean+abs(r(min))
		qui sum xhatmean
		replace xhatmean = xhatmean/(r(max))
		sum xp xhatmean
		qui sum 
	
  		qui reg xhatmean i.$id2
		qui predict hat_xhatmean if e(sample)==1,r
  		qui reg xp i.$id2
		qui predict hat_xp if e(sample)==1,r
		qui reg persrat_1 i.$id2
		qui predict hat_weeks if e(sample)==1,r
		pwcorr hat_* 
		pwcorr xhatmean xp persrat_1		
		sum xhatmean xp persrat_1
		
		*************** Asia *************
		twoway (line xhatmean year if country=="China" & year>=1950,lcol(red)ylab(0(.2)1)xtit("")) ///
			(line xp year if country=="China" & year>=1950,lcol(blue)legend(lab(1 "Gandhi-Sumner")lab(2 "GWF")lab(3 "Weeks") ///
			pos(1)ring(0)col(3)size(small))ytit(Personalism)ylab(0(.2)1)tit(China,size(large))xlab(1950(10)2010))  ///
			(line persrat_1 year if country=="China" & year>=1950,lcol(cyan)lpat(solid)saving(p1.gph,replace))
		twoway (line xhatmean year if cowcode==731,lcol(red)ylab(0(.2)1)xtit("")) ///
			(line xp year if cowcode==731,lcol(blue)legend(lab(1 "Gandhi-Sumner")lab(2 "GWF")lab(3 "Weeks") ///
			pos(6)ring(0)col(1))ytit(Personalism)ylab(0(.2)1)tit(North Korea,size(large))xlab(1950(10)2010))  ///
			(line persrat_1 year if cowcode==731,lcol(cyan)lpat(solid)saving(p2.gph,replace))
 		twoway (line xhatmean year if  cowcode==816 & year>=1976,lcol(red)ylab(0(.2)1)xtit("")) ///
			(line xp year if  cowcode==816 & year>=1976,lcol(blue)legend(lab(1 "Gandhi-Sumner")lab(2 "GWF")lab(3 "Weeks") ///
			pos(1)ring(0)col(1))ytit(Personalism)ylab(0(.2)1)tit(Vietnam,size(large))xlab(1980(10)2010))  ///
			(line persrat_1 year if  cowcode==816 & year>=1976,lcol(cyan)lpat(solid)saving(p3.gph,replace))
		*************** Africa *************
		twoway (line xhatmean year if country=="Sierra Leone" & year>=1950,lcol(red)ylab(0(.2)1)xtit("")) ///
			(line xp year if country=="Sierra Leone" & year>=1950,lcol(blue)legend(lab(1 "Gandhi-Sumner")lab(2 "GWF")lab(3 "Weeks") ///
			pos(1)ring(0)col(1))ytit(Personalism)ylab(0(.2)1)tit(Sierra Leone,size(large))xlab(1970(10)2000))  ///
			(line persrat_1 year if country=="Sierra Leone" & year>=1950,lcol(cyan)lpat(solid)saving(p4.gph,replace))
		twoway (line xhatmean year if country=="Togo" & year>=1950,lcol(red)ylab(0(.2)1)xtit("")) ///
			(line xp year if country=="Togo" & year>=1950,lcol(blue)legend(lab(1 "Gandhi-Sumner")lab(2 "GWF")lab(3 "Weeks") ///
			pos(5)ring(0)col(1))ytit(Personalism)ylab(0(.2)1)tit(Togo,size(large))xlab(1960(10)2010))  ///
			(line persrat_1 year if country=="Togo" & year>=1950,lcol(cyan)lpat(solid)saving(p5.gph,replace))		
		twoway (line xhatmean year if country=="Congo" & year>=1950,lcol(red)ylab(0(.2)1)xtit("")) ///
			(line xp year if country=="Congo" & year>=1950,lcol(blue)legend(lab(1 "Gandhi-Sumner")lab(2 "GWF")lab(3 "Weeks") ///
			pos(5)ring(0)col(1))ytit(Personalism)ylab(0(.2)1)tit(Congo,size(large))xlab(1960(10)2010))  ///
			(line persrat_1 year if country=="Togo" & year>=1950,lcol(cyan)lpat(solid)saving(p6.gph,replace))	
		twoway (line xhatmean year if country=="Uganda" & year>=1950,lcol(red)ylab(0(.2)1)xtit("")) ///
			(line xp year if country=="Uganda" & year>=1950,lcol(blue)legend(lab(1 "Gandhi-Sumner")lab(2 "GWF")lab(3 "Weeks") ///
			pos(5)ring(0)col(1))ytit(Personalism)ylab(0(.2)1)tit(Uganda,size(large))xlab(1960(10)2010))  ///
			(line persrat_1 year if country=="Uganda" & year>=1950,lcol(cyan)lpat(solid)saving(p7.gph,replace))	
		********* Latin America ************ 
		twoway (line xhatmean year if country=="Paraguay" & year>=1950,lcol(red)ylab(0(.2)1)xtit("")) ///
			(line xp year if country=="Paraguay" & year>=1950,lcol(blue)legend(lab(1 "Gandhi-Sumner")lab(2 "GWF")lab(3 "Weeks") ///
			pos(1)ring(0)col(1))ytit(Personalism)ylab(0(.2)1)tit(Paraguay,size(large))xlab(1950(10)2000))  ///
			(line persrat_1 year if country=="Paraguay" & year>=1950,lcol(cyan)lpat(solid)saving(p8.gph,replace))	
		twoway (line xhatmean year if country=="Panama" & year>=1968,lcol(red)ylab(0(.2)1)xtit("")) ///
			(line xp year if country=="Panama" & year>=1968,lcol(blue)legend(lab(1 "Gandhi-Sumner")lab(2 "GWF")lab(3 "Weeks") ///
			pos(11)ring(0)col(1))ytit(Personalism)ylab(0(.2)1)tit(Panama,size(large))xlab(1970(10)1990))  ///
			(line persrat_1 year if country=="Panama" & year>=1968,lcol(cyan)lpat(solid)saving(p9.gph,replace))	
		********* Middle East ************
		twoway (line xhatmean year if country=="Libya" & year>=1946,lcol(red)ylab(0(.2)1)xtit("")) ///
			(line xp year if country=="Libya" & year>=1946,lcol(blue)legend(lab(1 "Gandhi-Sumner")lab(2 "GWF")lab(3 "Weeks") ///
			pos(5)ring(0)col(1))ytit(Personalism)ylab(0(.2)1)tit(Libya,size(large))xlab(1950(10)2010))  ///
			(line persrat_1 year if country=="Libya" & year>=1946,lcol(cyan)lpat(solid)saving(p10.gph,replace))			
		twoway (line xhatmean year if country=="Iraq" & year>=1946,lcol(red)ylab(0(.2)1)xtit("")) ///
			(line xp year if country=="Iraq" & year>=1946,lcol(blue)legend(lab(1 "Gandhi-Sumner")lab(2 "GWF")lab(3 "Weeks") ///
			pos(5)ring(0)col(1))ytit(Personalism)ylab(0(.2)1)tit(Iraq,size(large))xlab(1950(10)2010))  ///
			(line persrat_1 year if country=="Iraq" & year>=1946,lcol(cyan)lpat(solid)saving(p11.gph,replace))	
		twoway (line xhatmean year if country=="Tunisia" & year>=1946,lcol(red)ylab(0(.2)1)xtit("")) ///
			(line xp year if country=="Tunisia" & year>=1946,lcol(blue)legend(lab(1 "Gandhi-Sumner")lab(2 "GWF")lab(3 "Weeks") ///
			pos(5)ring(0)col(1))ytit(Personalism)ylab(0(.2)1)tit(Tunisia,size(large))xlab(1960(10)2010))  ///
			(line persrat_1 year if country=="Tunisia" & year>=1946,lcol(cyan)lpat(solid)saving(p12.gph,replace))			
		grc1leg p1.gph p6.gph p11.gph p10.gph p2.gph p9.gph p8.gph p4.gph p5.gph p12.gph p7.gph p3.gph,col(4) ///
			xsize(3)ysize(6)iscale(.5)
	    gr export "$plots\Figure-G-1.pdf", as(pdf) replace
	 
	 
	 *****************************************************************
	 ****************  Simulations for selecting xc ******************
	 *****************************************************************
			global r=1000
			* test for Assassinations xc *
			use temp-assassinations,clear
			global x= "G_age lt leadermil loggdp logoil intwar civwar"
			global xmax=1
			gen test=.
 			gen xc=.
			gen n =_n
			gen b1=.
			gen b2=.
			gen t1=.
			gen t2=.
			forval i = 1/$r {
				global xc = `i'/$r
				qui gen xlow1 = xpers-$xc if xpers<=$xc
				qui replace xlow1=0 if xpers>$xc
				qui gen xhigh1 =  xpers-$xc if xpers>$xc 
				qui replace xhigh1=0 if xpers<=$xc 
				qui gen hi1 = xpers>$xc		
				qui gen xlow2=xpers-$xc if xpers<$xc
				qui replace xlow2=0 if xpers>=$xc
				qui gen xhigh2=xpers-$xc if xpers>=$xc
				qui replace xhigh2=0 if xpers<$xc
				qui gen hi2 = xpers>=$xc
 				qui tsset gwf_leaderid year
				qui reghdfe assa ayrs*   xlow1 xhigh1 hi1 if xpers<=$xmax,absorb(year gwf_caseid) cluster(gwf_leaderid year) 
				qui nlcom _b[xlow1] ,post
				mat b= e(b)
				local b = b[1,1]
				qui replace b1 = `b'  if n==`i'
				qui reghdfe assa ayrs*  xlow1 xhigh1 hi1 if xpers<=$xmax,absorb(year gwf_caseid) cluster(gwf_leaderid year) 
				qui test xlow1==0
				local r=r(p)
				qui replace t1=`r' if n==`i'
				qui test xhigh1==0,acc
				qui local t1=r(p)
				qui replace test=`t1' if n==`i' 
				qui test xhigh1==0
				local r=r(p)
				qui replace t2=`r' if n==`i'
				qui replace xc=$xc if n==`i'
				qui reghdfe assa ayrs*   xlow2 xhigh2 hi2 if xpers<=$xmax,absorb(year gwf_caseid) cluster(gwf_leaderid year)  
				qui nlcom _b[xhigh2] ,post
				mat b= e(b)
				local b = b[1,1]
				qui replace b2 = `b' if n==`i'
				qui drop  xlow* xhigh* hi*  
			}
			qui gen jtest  = ((t1^2+t2^2)^(.5))/2
			qui sum jtest if b1<0 & b2>0
			sum xc if jtest==r(min)
			twoway (line t1 xc if b1<0 & b2>0,sort lcol(gs1)lpat(dash)) (line t2 xc if b1<0 & b2>0,sort lcol(gs8)lpat(solid)) ///
				(line test xc if b1<0 & b2>0,sort lcol(red)lpat(blue) title(Assassinations) ylab(0(.2)1) saving(h1.gph,replace) ///
				legend(lab(1 "1st line p-value")lab(2 "2nd linep-value") lab(3 "Joint p-value") lab(4 "Test") ///
				size(small))ytit(p-value)xtit("x{sub:c}")subtitle("{&beta}{sub:1}<0; {&beta}{sub:2}>0")) ///
				(line jtest xc if b1<0 & b2>0,sort lcol(blue)lpat(solid))			
			
			* test for Regime chance coups xc *
			use temp-assassinations,clear
			global x= "G_age lt leadermil loggdp logoil intwar civwar"
			global xmax=1
			gen test=.
 			gen xc=.
			gen n =_n
			gen b1=.
			gen b2=.
			gen t1=.
			gen t2=.
			forval i = 1/$r {
				global xc = `i'/$r
				qui gen xlow1 = xpers-$xc if xpers<=$xc
				qui replace xlow1=0 if xpers>$xc
				qui gen xhigh1 =  xpers-$xc if xpers>$xc 
				qui replace xhigh1=0 if xpers<=$xc 
				qui gen hi1 = xpers>$xc		
				qui gen xlow2=xpers-$xc if xpers<$xc
				qui replace xlow2=0 if xpers>=$xc
				qui gen xhigh2=xpers-$xc if xpers>=$xc
				qui replace xhigh2=0 if xpers<$xc
				qui gen hi2 = xpers>=$xc
 				qui tsset gwf_leaderid year
				qui reghdfe chcoup cyrs*  xlow1 xhigh1 hi1 if xpers<=$xmax,absorb(year gwf_caseid) cluster(gwf_leaderid year) 
				qui nlcom _b[xlow1] ,post
				mat b= e(b)
				local b = b[1,1]
				qui replace b1 = `b'  if n==`i'
				qui reghdfe chcoup cyrs*  xlow1 xhigh1 hi1 if xpers<=$xmax,absorb(year gwf_caseid) cluster(gwf_leaderid year) 
 				qui test xlow1==0
				local r=r(p)
				qui replace t1=`r' if n==`i'
				qui test xhigh1==0,acc
				qui local t1=r(p)
				qui replace test=`t1' if n==`i' 
				qui test xhigh1==0
				local r=r(p)
				qui replace t2=`r' if n==`i'
				qui replace xc=$xc if n==`i'
				qui reghdfe chcoup cyrs*  xlow2 xhigh2 hi2 if xpers<=$xmax,absorb(year gwf_caseid) cluster(gwf_leaderid year) 
				qui nlcom _b[xhigh2] ,post
				mat b= e(b)
				local b = b[1,1]
				qui replace b2 = `b' if n==`i'
				qui drop  xlow* xhigh* hi*  
			}
			gen jtest  = ((t1^2+t2^2)^(.5))/2 
			qui sum jtest if b1>0 & b2<0
			sum xc if jtest==r(min)
			qui sum test if b1>0 & b2<0
			sum xc if test==r(min)
			qui sum t1 if b1>0 & b2<0
			sum xc if t1==r(min)
			qui sum t2 if b1>0 & b2<0
			sum xc if t2==r(min)
 			twoway (line t1 xc if  b1>0 & b2<0,sort lcol(gs1)lpat(dash)) ///
				(line t2 xc if   b1>0 & b2<0,sort lcol(gs8)lpat(solid)) ///
				(line test xc if   b1>0 & b2<0,sort lcol(red)lpat(solid) title(Regime change coups) ///
				ylab(0(.2)1) saving(h2.gph,replace) ///
				legend(lab(1 "1st line p-value")lab(2 "2nd line p-value")lab(3 "Joint p-value")lab(4 "Test") ///
				size(small))ytit(p-value)xtit("x{sub:c}") subtitle("{&beta}{sub:1}>0; {&beta}{sub:2}<0")) ///
				(line jtest xc if   b1>0 & b2<0,sort lcol(blue)lpat(solid))
 				
			gr combine h1.gph h2.gph,xsize(10)iscale(.8)note("test=(({it:p{sub:1}}{sup:2} + {it:p{sub:2}}{sup:2}){sup:0.5})/2",pos(6))
			gr export "$plots\Figure-D-3.pdf", as(pdf) replace
			
			forval i=1/2 {
				erase h`i'.gph
				erase d`i'.gph
				erase fit`i'.gph
				erase fit`i'A.gph
				erase fit`i'CH.gph
				erase fit`i'SH.gph
				erase fitT`i'A.gph
				erase fitT`i'CH.gph
				erase fitT`i'SH.gph
			}
			erase fit3.gph
			erase d3.gph
			erase h3.gph
			forval i=1/12 {
				erase p`i'.gph
			}
***************************** The End  *********************************
			
			log close
	 